package com.company.test27_28;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Administrator on 2016.11.9.
 */
public class Test2701 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String fileName=input.next();
        File file=new File(fileName);
        try{
            input=new Scanner(file);
        }catch (FileNotFoundException e){
            System.out.println("文件不存在");
            return;
        }

        int n=Integer.valueOf(input.nextLine());
        List<List<Integer>> edges=new ArrayList<>();
        for(int i=0;i<n;i++){
            String line=input.nextLine();
            Scanner deal=new Scanner(line);
            ArrayList<Integer> edge=new ArrayList<>();

            while (deal.hasNext()){
                edge.add(deal.nextInt());
            }
            edges.add(edge);
        }

        System.out.println("The number of vertices is "+n);
        for(List<Integer> edge:edges){
            System.out.print("Vertex "+edge.get(0)+": ");
            for(int i=1;i<edge.size();i++){
                System.out.printf("(%d,%d) ",edge.get(0),edge.get(i));
            }
            System.out.println();
        }

        if(isConnect(edges)){
            System.out.println("The graph is connected");
        }else {
            System.out.println("The graph isn't connected");
        }

    }

    public static boolean isConnect(List<List<Integer>> list){
        List<AbstractGraph.Edge> edges=new ArrayList<>();
        for(int i=0;i<list.size();i++){
            for(int j=1;j<list.get(i).size();j++){
                AbstractGraph.Edge edge=new AbstractGraph.Edge(list.get(i).get(0),list.get(i).get(j));
                edges.add(edge);
            }
        }
        Graph<Integer> graph=new UnweightedGraph<Integer>(edges,list.size());

        if(graph.bfs(0).getSearchOrders().size()==list.size()){
            return true;
        }
        return false;
    }
}
